//
// load features
//
feature.load("file", "java", "zip", "ivy");
//
// setup
//
var version = -1;
var versionFile = file("version");
if (versionFile.exists()) {
    version = eval(versionFile.read());
}
version++;
console.log("version", version);
//
// lib dir / list
//
var svn_flt = Filter.not(/.*\.svn.*/);

var lib = fileset("lib").filter(svn_flt).filter(/.*\.jar/);
var src = fileset("src").filter(svn_flt);
var javaSrc = src.filter(/.*\.java/);
var jsSrc = src.filter(/.*\.js/);
var buildDir = file("build");
var classDir = file(buildDir, "classes");
var classSet = fileset(classDir);
var javaZip = file(buildDir, "jsclay.jar");
//
// clean task
//
var clean = task.create(function () {
    buildDir.remove();
});
//
// resolve task
//
var resolve = task.create(function () {
    clean();
    ivy.configure({
        location: "http://ivy.dev.midasplayer.com/repository/",
        resolveDir: libDir
    });
    ivy.dependencies({
        runtime: [
            {org: "king", name: "plataforma", rev: "+", conf: "runtime"}
        ]
    });
    ivy.resolve("runtime");
});
//
// compile task
//
var compile = task.create(function () {
    clean();
    classDir.makeDir();
    java.compile(lib, javaSrc, classDir);
});

//
// build task
//
var build = task.create(function () {
    compile();
    jsSrc.copyInto(classDir);
});
//
// makeZip
//
var make = task.create(function () {
    build();
    classSet.zip(javaZip);
/*    zip.pack(classSet, javaZip, function (f) {
        return true;
    }); */
});

var dist = task.create(function() {
    make();
    versionFile.write(version);
});

dist();
